package com.chenfan.mcn.enums;

import com.alibaba.fastjson.JSONObject;
import com.chenfan.mcn.constant.NumberCst;
import com.chenfan.mcn.model.vo.StarRateCardDetailQueryVO;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 刊例配置-基础信息-枚举
 *
 * @author wulg
 * @date 2021-12-28
 **/
@Getter
@AllArgsConstructor
public enum RateCardBasicInfoEnum {

    /**
     * 定义统一接口（含基础信息、平台信息）给前端-自动渲染
     */
    STAR_HEAD_IMG("head_img", "红人头像", false, true, true, 100),
    STAR_NICKNAME("star_nickname", "红人昵称", true, false, false, 101),
    STAR_NAME("star_name", "真实姓名", true, false, false, 102),
    STAR_ADDRESS("star_address", "所在地", false, false, false, 103),
    GENDER("gender", "性别", true, false, false, 104),
    STAR_CLASSIFICATION("star_classification", "红人分类",false, false, false, 105),
    GOOD_AT_TYPE("good_at_type", "擅长类型", false,false, false, 106),
    STAR_LABEL("star_label", "红人标签", false,false, false, 107),
    MAIN_ACTIVE_PLATFORMS("main_active_platforms", "主要活跃平台",false, false, false, 108),
    STAR_AGENT_NAME("star_agent_name", "经纪人", true, true, false, 109),
    ;

    /**
     * 字段名称-跟红人基础信息表对应
     */
    private final String fieldName;

    /**
     * 字段描述
     */
    private final String fieldDesc;

    /**
     * 是否显示
     */
    private final boolean display;

    /**
     * 是否默认勾选
     */
    private final boolean autoSelect;

    /**
     * 是否是图片
     */
    private final boolean isImage;

    /**
     * 排序
     */
    private final int order;

    /**
     * 转成JSONObject对象
     * @return
     */
    public static List<JSONObject> toJsonObject() {
        List<JSONObject> list = new ArrayList<>();
        for (RateCardBasicInfoEnum item : RateCardBasicInfoEnum.values()) {
            if(!item.display) {
                continue;
            }
            JSONObject jsonObject = new JSONObject(4, true);
            jsonObject.put("fieldName", item.getFieldName());
            jsonObject.put("fieldDesc", item.getFieldDesc());
            jsonObject.put("autoSelect", item.autoSelect);
            jsonObject.put("order", item.getOrder());
            list.add(jsonObject);
        }
        return list;
    }

    /**
     * 根据fieldName集合获取fieldDesc集合
     * @param fieldNameList
     * @return
     */
    public static List<String> getDescList(List<String> fieldNameList) {
        if(CollectionUtils.isNotEmpty(fieldNameList)) {
            List<String > fieldDescList = new ArrayList<>(fieldNameList.size());
            for (RateCardBasicInfoEnum item : RateCardBasicInfoEnum.values()) {
                if (fieldNameList.contains(item.fieldName)){
                    fieldDescList.add(item.fieldDesc);
                }
            }
            return fieldDescList;
        }
        return new ArrayList<>(0);
    }

    /**
     * 获取table头信息
     * @param fieldNameList
     * @return
     */
    public static List<StarRateCardDetailQueryVO.TableHead> getTableHead(List<String> fieldNameList) {
        if(CollectionUtils.isNotEmpty(fieldNameList)) {
            List<StarRateCardDetailQueryVO.TableHead> tableHeadList = new ArrayList<>(fieldNameList.size());
            for (RateCardBasicInfoEnum item : RateCardBasicInfoEnum.values()) {
                if (fieldNameList.contains(item.fieldName)){
                    tableHeadList.add(new StarRateCardDetailQueryVO.TableHead(NumberCst.ONE, item.getFieldName(), item.getFieldDesc(), item.autoSelect, item.isImage, item.order));
                }
            }
            return tableHeadList;
        }
        return new ArrayList<>(0);
    }

    /**
     * 获取默认勾选的
     * @return
     */
    public static List<String> getAutoSelectList(){
        List<String> selectedList = new ArrayList<>();
        for (RateCardBasicInfoEnum item : RateCardBasicInfoEnum.values()) {
            if (item.autoSelect){
                selectedList.add(item.fieldDesc);
            }
        }
        return selectedList;
    }
}
